package ru.housewife.form;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Form object for
 * @see ru.housewife.model.WaresGroup
 *
 * @author Alexander Troshanin
 */
public class WaresGroupForm implements Comparable<WaresGroupForm> {

    private long id;

    private String name;

    private WaresGroupForm parent;

    private List<WaresGroupForm> childs;

    private List<WareForm> wares;

    private boolean defaultGroup;

    private int order;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public WaresGroupForm getParent() {
        return parent;
    }

    public void setParent(WaresGroupForm parent) {
        this.parent = parent;
    }

    public List<WaresGroupForm> getChilds() {
        return childs == null ? Collections.<WaresGroupForm>emptyList() : childs;
    }

    public void setChilds(List<WaresGroupForm> childs) {
        this.childs = childs;
    }

    public List<WareForm> getWares() {
        return wares == null ? Collections.<WareForm>emptyList() : wares;
    }

    public void setWares(List<WareForm> wares) {
        this.wares = wares;
    }

    public void addWare(WareForm wareForm) {
        if (wares == null) {
            wares = new ArrayList<WareForm>();
        }
        wares.add(wareForm);
    }

    public boolean isDefaultGroup() {
        return defaultGroup;
    }

    public void setDefaultGroup(boolean defaultGroup) {
        this.defaultGroup = defaultGroup;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    @Override
    public int compareTo(WaresGroupForm that) {
        int thisVal = this.order;
        int thatVal = that.order;
        return (thisVal < thatVal ? -1 : (thisVal == thatVal ? 0 : 1));
    }
}
